const util = require('../../../../../utils/util.js');
const api = require('../../../../../config/api.js');
const recorderManager = wx.getRecorderManager();
var recordInterval = null;
const app = getApp(); 
Page({

  /**
   * 页面的初始数据
   */
  data: {
    posters: { "isupload": false, "ip": "", "url": "", "isupdate": false, "size": 0 },//海报信息
    platform: "",//客户端平台
    selectAllLable: [],// 选中的类目标签
    selectLableTextArray: [],// 选中的类目标签文字版
    interestJoinList: [],// 组员信息
    circleInfo: {},// 圈子信息
    circleid: '',//圈子id
    energyInfoResultShow: false,//是否显示获取橙贝的弹窗
    tabs: { "tabsActive": 0, "circleList": [], "baobeiList": [] },// 推荐内容
    nickName: "",//当前用户的昵称
    isOpenDiaShow: false,// 是否有弹窗
    dataInfo: { "albumInfo": [], "appreciateInfo": {}, "recommendInfo": {}, "imagePopupShow": false, "audioOauhRefusedDialogShow": false, "isRecorderStart": false, "voiceDialogShow": false, "voiceUpdateIndex": "", "voiceUpdateTitle": "", "videoPopupShow": false, "linkPopupShow": false, "linkErrorDialogShow": false, "linkNameDialogShow": false, "linkAlbumInfoIndex": false, "recommendPopupShow": false, "albumInfoDeleteIndex": "", "voiceDialogDeleteShow": false, "addressOauhRefusedDialogShow": false, "returnMoneyText": "", "returnPrice": "", "returnPreferentialSettings": "", "returnAmountDetailSize": "", "returnItemTypeIdentification": "", "returnProjectdateStart": "", "returnProjectdateEnd": "", "projectdateStart": "", "projectdateEnd": "", "projectdateStartLimit": "", "returnProjectdateidentification": "", "projectdateEndLimit": "", "preferentialdateStartMin": "", "preferentialdateEndMax": "", "validityStartMin": "", "validityEndMax": "" },//详情信息
    mainUser: {},// 圈主信息
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var _this = this;
    var platform = wx.getSystemInfoSync().platform;
    _this.setData({
      platform: platform,
      nickName: app.globalData.logininfo.userInfo.nickName,
      circleid: options.circleid,
      energyInfoResultShow: options.energyInfoResults != null && (options.energyInfoResults == true || options.energyInfoResults == 'true') ? true : false
    })

    //加载圈子数据
    _this.getCircleInfo();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var _this = this;
    var posters = _this.data.posters;
    var isupdate = posters.isupdate;
    if (isupdate == true) {
      _this.setData({
        ["circleInfo.postersIsupload"]: posters.isupload,//是否需要上传海报
        ["circleInfo.postersIp"]: posters.ip,
        ["circleInfo.posterImageUrl"]: posters.url
      })
    }
    _this.getAmountScope();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var _this = this;
    var id = _this.data.circleid;
    var openid = app.globalData.logininfo.openid;
    var nickName = _this.data.nickName;
    var interest_title = _this.data.circleInfo.title;
    if (interest_title.length > 17) {
      interest_title = interest_title.substring(0, 17) + "...";
    }
    var title = nickName + "邀请你打卡#" + interest_title + "#";
    return {
      title: title,
      path: 'pages/home/shareJump/shareJump?id=' + id + "&type=" + util.getShareType("circle") + "&shareOpenid=" + openid + "&isCheckLogin=1"
    }
  },

  /**
   * 详情设置
   */
  editorAlbumInfo: function (e) {
    var _this = this;
    var type = e.currentTarget.dataset.type;
    var albumInfo = _this.data.dataInfo.albumInfo;
    var albumInfoLength = albumInfo.length;
    switch (type) {
      case "1":
        // 文字
        var info = {};
        info.albumType = type;
        info.focus = true;
        info.autoheight = true;
        info.value = "";
        info.dataType = "0";
        albumInfo.push(info);
        _this.setData({
          ["dataInfo.albumInfo"]: albumInfo
        })
        break;
      case "2":
        // 图片
        _this.setData({
          ["dataInfo.imagePopupShow"]: true,
          isOpenDiaShow: true
        })
        break;
      case "3":
        // 音频
        wx.getSetting({
          success(res) {
            if (!res.authSetting['scope.record']) {
              // 未授权
              wx.authorize({
                scope: 'scope.record',
                success() {
                  _this.recorderStart(albumInfo, albumInfoLength, type);
                },
                fail: function () {
                  // 拒绝授权
                  _this.setData({
                    ["dataInfo.audioOauhRefusedDialogShow"]: true,
                    isOpenDiaShow: true
                  })
                }
              })
            } else {
              // 已授权
              _this.recorderStart(albumInfo, albumInfoLength, type);
            }
          }
        })
        break;
      case "4":
        // 视频
        _this.setData({
          ["dataInfo.videoPopupShow"]: true,
          isOpenDiaShow: true
        })
        break;
      case "5":
        // 链接
        _this.setData({
          ["dataInfo.linkPopupShow"]: true,
          isOpenDiaShow: true
        })
        break;
      case "6":
        // 位置
        wx.getSetting({
          success(res) {
            if (!res.authSetting['scope.userLocation']) {
              // 未授权
              wx.authorize({
                scope: 'scope.userLocation',
                success() {
                  _this.albumInfoPositionStart(albumInfo, type);
                },
                fail: function () {
                  // 拒绝授权
                  _this.setData({
                    ["dataInfo.addressOauhRefusedDialogShow"]: true,
                    isOpenDiaShow: true
                  })
                }
              })
            } else {
              // 已授权
              _this.albumInfoPositionStart(albumInfo, type);
            }
          }
        })
        break;
      case "7":
        // 赞赏
        var appreciateInfo = {};
        appreciateInfo.state = 1;
        appreciateInfo.dataType = "0";
        _this.setData({
          ["dataInfo.appreciateInfo"]: appreciateInfo
        })
        break;
      case "8":
        // 推荐
        _this.recommendPopupShow();
        break;
    }
  },

  /**
   * 编辑详情文字的焦点移出事件
   */
  albumInfoTextareaBlur: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    var isSwitchEmoji = false;
    if (e.detail != null && e.detail.isSwitchEmoji != null) {
      isSwitchEmoji = e.detail.isSwitchEmoji;
    }
    if (!isSwitchEmoji) {
      _this.setData({
        ["dataInfo.albumInfo[" + index + "].focus"]: false,
        ["dataInfo.albumInfo[" + index + "].autoheight"]: false
      })
    }
  },

  /**
   * 编辑详情文字的焦点移出事件
   */
  albumInfoTextareaInput: function (e) {
    var _this = this;
    var value = e.detail.value;
    var index = e.currentTarget.dataset.index;
    _this.setData({
      ["dataInfo.albumInfo[" + index + "].value"]: value
    })
  },

  /**
   * 编辑详情文字的聚焦事件
   */
  albumInfoTextareaFocus: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    _this.setData({
      ["dataInfo.albumInfo[" + index + "].focus"]: true,
      ["dataInfo.albumInfo[" + index + "].autoheight"]: true
    })
  },

  /**
   * 图片弹出层选择
   */
  imageSelect: function (e) {
    var _this = this;
    var type = e.currentTarget.dataset.type;
    var albumInfo = _this.data.dataInfo.albumInfo;
    if (type == 1) {
      // 拍照
      wx.chooseImage({
        count: 9,
        sizeType: ['original', 'compressed'],
        sourceType: ['camera'],
        success(res) {
          var info = {};
          info.albumType = 2;
          info.tempFiles = res.tempFiles;
          info.dataType = "0";
          albumInfo.push(info);
          _this.setData({
            ["dataInfo.albumInfo"]: albumInfo,
            ["dataInfo.imagePopupShow"]: false,
            isOpenDiaShow: false
          })
        }
      })
    } else if (type == 2) {
      // 从手机相册选择
      wx.chooseImage({
        count: 9,
        sizeType: ['original', 'compressed'],
        sourceType: ['album'],
        success(res) {
          var info = {};
          info.albumType = 2;
          info.tempFiles = res.tempFiles;
          info.dataType = "0";
          albumInfo.push(info);
          _this.setData({
            ["dataInfo.albumInfo"]: albumInfo,
            ["dataInfo.imagePopupShow"]: false,
            isOpenDiaShow: false
          })
        }
      })
    } else if (type == 3) {
      //从微信导入图片
      wx.chooseMessageFile({
        count: 9,
        type: 'image',
        success(res) {
          var info = {};
          info.albumType = 2;
          info.tempFiles = res.tempFiles;
          info.dataType = "0";
          albumInfo.push(info);
          _this.setData({
            ["dataInfo.albumInfo"]: albumInfo,
            ["dataInfo.imagePopupShow"]: false,
            isOpenDiaShow: false
          })
        }
      })
    }
  },

  /**
   * 预览图片
   */
  previewImage: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    var yindex = e.currentTarget.dataset.yindex;
    var albumInfo = _this.data.dataInfo.albumInfo;
    var urls = [];
    var current = albumInfo[index].tempFiles[yindex].path;
    for (var i = 0; i < albumInfo.length; i++) {
      if (albumInfo[i].albumType == 2) {
        for (var y = 0; y < albumInfo[i].tempFiles.length; y++) {
          urls.push(albumInfo[i].tempFiles[y].path);
        }
      }
    }
    wx.previewImage({
      current: current, // 当前显示图片的http链接
      urls: urls // 需要预览的图片http链接列表
    })
  },

  /**
   * 关闭图片弹出层
   */
  imagePopupClose: function () {
    var _this = this;
    _this.setData({
      ["dataInfo.imagePopupShow"]: false,
      isOpenDiaShow: false
    })
  },

  /**
   * 开始录音
   */
  recorderStart: function (albumInfo, albumInfoLength, type) {
    var _this = this;
    var isPlay = false;//是否可以录音
    var albumTypeIsRecorderCount = 0;
    for (var i = 0; i < albumInfoLength; i++) {
      if (albumInfo[i].albumType == type) {
        albumTypeIsRecorderCount++;
        if (albumInfo[i].state == "2") {
          isPlay = true;
          break;
        }
      }
    }
    if (albumTypeIsRecorderCount == 0) {
      isPlay = true;
    }
    if (isPlay) {
      var info = {};
      info.albumType = type;
      info.state = "1";// 1正在录音  2录音完毕（state==2的时候，playState无效）
      info.playState = "1";// 1正常录音  2暂停录音
      info.totalTime = 0;
      info.totalDate = "00:00";
      info.isVoiceDialogShow = true;
      info.title = "";
      info.dataType = "0";
      albumInfo.push(info);
      _this.setData({
        ["dataInfo.albumInfo"]: albumInfo,
        ["dataInfo.isRecorderStart"]: true
      })

      const recorderOptions = {
        duration: util.getAudioFileMaxTime("circle"),
        format: 'mp3'
      }
      //开始录音
      recorderManager.start(recorderOptions);

      // 定时器计算录音时间
      _this.doRecordInterval(albumInfoLength);

      // 录音结束
      recorderManager.onStop((res) => {
        _this.stopRecorderExecute(albumInfoLength, res);
      });

      // 录音中断
      recorderManager.onInterruptionBegin((res) => {
        recorderManager.stop();
        _this.setData({
          ["dataInfo.albumInfo[" + albumInfoLength + "].isVoiceDialogShow"]: false
        })
        _this.stopRecorderExecute(albumInfoLength, res);
      });
    }
  },

  /**
   * 开始录音
   */
  recorderStart2: function (index) {
    var _this = this;
    var info = {};
    info.albumType = 3;
    info.state = "1";// 1正在录音  2录音完毕（state==2的时候，playState无效）
    info.playState = "1";// 1正常录音  2暂停录音
    info.totalTime = 0;
    info.totalDate = "00:00";
    info.isVoiceDialogShow = true;
    _this.setData({
      ["dataInfo.albumInfo[" + index + "]"]: info,
      ["dataInfo.isRecorderStart"]: true
    })

    const recorderOptions = {
      duration: util.getAudioFileMaxTime("circle"),
      format: 'mp3'
    }
    //开始录音
    recorderManager.start(recorderOptions);

    // 定时器计算录音时间
    _this.doRecordInterval(index);

    // 录音结束
    recorderManager.onStop((res) => {
      _this.stopRecorderExecute(index, res);
    });

    // 录音中断
    recorderManager.onInterruptionBegin((res) => {
      recorderManager.stop();
      _this.setData({
        ["dataInfo.albumInfo[" + index + "].isVoiceDialogShow"]: false
      })
      _this.stopRecorderExecute(index, res);
    });

  },

  /**
   * 定时器计算录音时间
   */
  doRecordInterval: function (index) {
    var _this = this;
    if (recordInterval == null) {
      recordInterval = setInterval(function () {
        var nowAlbumInfo = _this.data.dataInfo.albumInfo[index];
        var totalTime = nowAlbumInfo.totalTime + 1;
        var totalDate = util.digitalFormatTime(totalTime);
        _this.setData({
          ["dataInfo.albumInfo[" + index + "].totalTime"]: totalTime,
          ["dataInfo.albumInfo[" + index + "].totalDate"]: totalDate
        });
      }, 1000);
    }
  },

  /**
   * 停止录音后的业务代码
   */
  stopRecorderExecute: function (index, tempFile) {
    var _this = this;
    _this.doClearInterval();
    var nowAlbumInfo = _this.data.dataInfo.albumInfo[index];
    if (nowAlbumInfo != null) {
      var isVoiceDialogShow = nowAlbumInfo.isVoiceDialogShow;
      if (isVoiceDialogShow) {
        var totalTime = parseInt(tempFile.duration / 1000);
        nowAlbumInfo.state = "2";
        nowAlbumInfo.src = tempFile.tempFilePath;
        nowAlbumInfo.title = "";
        nowAlbumInfo.currentTime = 0;
        nowAlbumInfo.totalTime = totalTime;
        nowAlbumInfo.fileSize = tempFile.fileSize;
        nowAlbumInfo.startDate = "00:00";
        nowAlbumInfo.totalDate = util.digitalFormatTime(totalTime);
        nowAlbumInfo.voiceBoFangImage = api.AudioNoBoFangImage_Name;
        _this.setData({
          ["dataInfo.albumInfo[" + index + "]"]: nowAlbumInfo,
        })
        _this.voiceDialogShow(index);
      }
    }
    _this.setData({
      ["dataInfo.isRecorderStart"]: false
    })
  },

  /**
   * 清除定时器
   */
  doClearInterval: function () {
    clearInterval(recordInterval);
    recordInterval = null;
  },

  /**
   * 是否展示音频dialog
   */
  voiceDialogShow: function (e) {
    var _this = this;
    var voiceDialogShow = _this.data.dataInfo.voiceDialogShow;
    var index = e.currentTarget == null ? e : e.currentTarget.dataset.index;
    var title = _this.data.dataInfo.albumInfo[index].title;
    if (voiceDialogShow) {
      // 关闭
      if (title != null && title.trim().length <= 0) {
        title = _this.data.nickName + "的音频"
      }
      _this.setData({
        isOpenDiaShow: false,
        ["dataInfo.voiceDialogShow"]: false,
        ["dataInfo.voiceUpdateIndex"]: "",
        ["dataInfo.albumInfo[" + index + "].title"]: title,
        ["dataInfo.voiceUpdateTitle"]: ""
      })
    } else {
      // 开启
      _this.setData({
        isOpenDiaShow: true,
        ["dataInfo.voiceDialogShow"]: true,
        ["dataInfo.voiceUpdateIndex"]: index,
        ["dataInfo.voiceUpdateTitle"]: title
      })
    }
  },

  /**
   * 停止录音
   */
  stopRecorder: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    recorderManager.stop();
    recorderManager.onStop((res) => {
      _this.stopRecorderExecute(index, res);
    });
  },

  /**
   * 录音音频名称的修改
   */
  voiceUpdateTitle: function (e) {
    var _this = this;
    var title = e.detail;
    var index = _this.data.dataInfo.voiceUpdateIndex;
    if (title.trim().length <= 0) {
      title = _this.data.nickName + "的录音音频";
    }
    _this.setData({
      ["dataInfo.albumInfo[" + index + "].title"]: title
    })
  },

  /**
   * 清空录音
   */
  clearRecorder: function (e) {
    var _this = this;
    var albumInfo = _this.data.dataInfo.albumInfo;
    var albumInfoLength = albumInfo.length;
    var index = e.currentTarget.dataset.index;
    _this.doClearInterval();
    _this.setData({
      ["dataInfo.albumInfo[" + index + "].isVoiceDialogShow"]: false
    })
    recorderManager.stop();

    setTimeout(function () {
      // 音频
      wx.getSetting({
        success(res) {
          if (!res.authSetting['scope.record']) {
            // 未授权
            wx.authorize({
              scope: 'scope.record',
              success() {
                _this.recorderStart2(index);
              },
              fail: function () {
                // 拒绝授权
                _this.setData({
                  ["dataInfo.audioOauhRefusedDialogShow"]: true
                })
              }
            })
          } else {
            // 已授权
            _this.recorderStart2(index);
          }
        }
      })
    }, 100)
  },

  /**
   * 暂停录音
   */
  pauseRecorder: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    _this.setData({
      ["dataInfo.albumInfo[" + index + "].playState"]: "2"
    });
    recorderManager.pause();
    _this.doClearInterval();
  },

  /**
   * 继续录音
   */
  resumeRecorder: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    _this.setData({
      ["dataInfo.albumInfo[" + index + "].playState"]: "1"
    })
    recorderManager.resume();
    _this.doRecordInterval(index);
  },

  /**
   * 播放或暂停动作
   */
  voiceBoFang: function (e) {
    var _this = this;
    var src = e.currentTarget.dataset.src;
    var index = e.currentTarget.dataset.index;
    var title = e.currentTarget.dataset.title;
    var currentTime = e.currentTarget.dataset.currenttime;
    var voiceBoFangImage = e.currentTarget.dataset.voiceimage;
    var backgroundAudioManager = wx.getBackgroundAudioManager();//获取全局唯一的背景音频管理器
    if (voiceBoFangImage == api.AudioBoFangImage_Name) {
      // 切换至暂停状态
      backgroundAudioManager.pause();//暂停播放音乐
      _this.setData({
        ["dataInfo.albumInfo[" + index + "].voiceBoFangImage"]: api.AudioNoBoFangImage_Name
      });
    } else {
      // 切换至播放状态
      wx.stopBackgroundAudio();//暂停正在播放音乐
      backgroundAudioManager.startTime = currentTime;//设置音乐开始时间
      backgroundAudioManager.title = title;
      backgroundAudioManager.src = src;
      backgroundAudioManager.play();
      //    背景音频自然播放结束事件
      backgroundAudioManager.onEnded(function () {
        _this.setData({
          ["dataInfo.albumInfo[" + index + "].currentTime"]: 0,
          ["dataInfo.albumInfo[" + index + "].voiceBoFangImage"]: api.AudioNoBoFangImage_Name,
          ["dataInfo.albumInfo[" + index + "].startDate"]: "00:00"
        });
      })
      //背景音频播放进度更新事件
      backgroundAudioManager.onTimeUpdate(function (callback) {
        var position = Math.round(backgroundAudioManager.currentTime);
        var voiceStartDate = util.digitalFormatTime(position);
        _this.setData({
          ["dataInfo.albumInfo[" + index + "].currentTime"]: backgroundAudioManager.currentTime,
          ["dataInfo.albumInfo[" + index + "].startDate"]: voiceStartDate
        });
      })

      _this.setData({
        ["dataInfo.albumInfo[" + index + "].voiceBoFangImage"]: api.AudioBoFangImage_Name
      });
    }
  },

  /**
   * 播放音乐（滚动条事件）
   */
  voiceSlider: function (e) {
    var _this = this;
    var position = e.detail.value;
    var src = e.currentTarget.dataset.src;
    var index = e.currentTarget.dataset.index;
    var title = e.currentTarget.dataset.title;
    var currentTime = e.currentTarget.dataset.currenttime;
    var voiceBoFangImage = e.currentTarget.dataset.voiceimage;
    var voiceStartDate = util.digitalFormatTime(position);
    var backgroundAudioManager = wx.getBackgroundAudioManager();//获取全局唯一的背景音频管理器
    if (voiceBoFangImage == api.AudioBoFangImage_Name) {
      //正在播放状态：不知道为什么，录音的在调用backgroundAudioManager.seek(Math.floor(position))方法无效，所以改成一下这种方式
      e.currentTarget.dataset.currenttime = position;
      e.currentTarget.dataset.voiceimage = api.AudioNoBoFangImage_Name;
      _this.voiceBoFang(e);
    } else {
      // 未播放状态
      _this.setData({
        ["dataInfo.albumInfo[" + index + "].currentTime"]: position,
        ["dataInfo.albumInfo[" + index + "].startDate"]: voiceStartDate
      });
    }
  },

  /**
   * 视频弹出层选择
   */
  videoSelect: function (e) {
    var _this = this;
    var type = e.currentTarget.dataset.type;
    var albumInfo = _this.data.dataInfo.albumInfo;
    if (type == 1) {
      // 拍摄
      wx.chooseVideo({
        sourceType: ['camera'],
        maxDuration: util.getVideoFileMaxTime("circle"),
        camera: 'back',
        success(res) {
          var size = res.size;
          var width = res.width;
          var height = res.height;
          var duration = parseInt(res.duration);
          var tempFilePath = res.tempFilePath;
          var id = "myVideo" + new Date().getTime();
          var totalDate = util.digitalFormatTime(duration);
          var info = {};
          info.id = id;
          info.size = size;
          info.width = width;
          info.height = height;
          info.albumType = 4;
          info.src = tempFilePath;
          info.totalTime = duration;
          info.totalDate = totalDate;
          info.dataType = "0";
          albumInfo.push(info);
          _this.setData({
            ["dataInfo.albumInfo"]: albumInfo,
            ["dataInfo.videoPopupShow"]: false,
            isOpenDiaShow: false
          })
        }
      })
    } else if (type == 2) {
      // 从手机相册选择
      wx.chooseVideo({
        sourceType: ['album'],
        maxDuration: util.getVideoFileMaxTime("circle"),
        camera: 'back',
        success(res) {
          var size = res.size;
          var maxSize = util.getVideoFileMaxSize("circle");
          if ((size / 1024 / 1024) > maxSize) {
            util.dialogAlert("视频大小超出" + maxSize + "M");
            return;
          }

          var width = res.width;
          var height = res.height;
          var duration = parseInt(res.duration);
          var tempFilePath = res.tempFilePath;
          var id = "myVideo" + new Date().getTime();
          var totalDate = util.digitalFormatTime(duration);
          var info = {};
          info.id = id;
          info.size = size;
          info.width = width;
          info.height = height;
          info.albumType = 4;
          info.src = tempFilePath;
          info.totalTime = duration;
          info.totalDate = totalDate;
          info.dataType = "0";
          albumInfo.push(info);
          _this.setData({
            ["dataInfo.albumInfo"]: albumInfo,
            ["dataInfo.videoPopupShow"]: false,
            isOpenDiaShow: false
          })
        }
      })
    } else if (type == 3) {
      //从微信导入视频
      wx.chooseMessageFile({
        count: 1,
        type: 'video',
        success(res) {
          var tempFiles = res.tempFiles[0];
          var size = tempFiles.size;
          var maxSize = util.getVideoFileMaxSize("circle");
          if ((size / 1024 / 1024) > maxSize) {
            util.dialogAlert("视频大小超出" + maxSize + "M");
            return;
          }

          var tempFilePath = tempFiles.path;
          var id = "myVideo" + new Date().getTime();
          var info = {};
          info.id = id;
          info.size = size;
          info.width = 0;
          info.height = 0;
          info.totalTime = 0;
          info.totalDate = "";
          info.albumType = 4;
          info.src = tempFilePath;
          info.dataType = "0";
          albumInfo.push(info);

          _this.setData({
            ["dataInfo.albumInfo"]: albumInfo,
            ["dataInfo.videoPopupShow"]: false,
            isOpenDiaShow: false
          });
        }
      })
    }
  },

  /**
   * 关闭视频弹出层
   */
  videoPopupClose: function () {
    var _this = this;
    _this.setData({
      ["dataInfo.videoPopupShow"]: false,
      isOpenDiaShow: false
    })
  },

  /**
   * 视频播放
   */
  videoPlay: function (e) {
    var _this = this;
    var videoId = e.currentTarget.dataset.id;
    this.videoContext = wx.createVideoContext(videoId);
    this.videoContext.pause();
  },

  /**
   * 关闭链接的底部弹窗
   */
  linkPopupClose: function () {
    var _this = this;
    _this.setData({
      ["dataInfo.linkPopupShow"]: false,
      isOpenDiaShow: false
    })
  },

  /**
   * 链接底部弹出的选择
   */
  linkSelect: function (e) {
    var _this = this;
    var albumInfo = _this.data.dataInfo.albumInfo;
    _this.linkPopupClose();
    var type = e.currentTarget.dataset.type;
    if (type == 1) {
      // 粘贴公众号文章链接
      var info = {};
      info.albumType = 5;
      info.type = 1;
      info.name = "";
      info.ip = "";
      info.value = "";
      info.focus = true;
      info.textareaPlaceholderShow = true;
      info.state = "1";
      info.dataType = "0";
      albumInfo.push(info);
      _this.setData({
        ["dataInfo.albumInfo"]: albumInfo
      })
    } else if (type == 2) {
      // 从微信导入文件
      wx.chooseMessageFile({
        count: 1,
        type: 'file',
        success(res) {
          var tempFile = res.tempFiles[0];
          var path = tempFile.path;
          var pathIndex1 = path.lastIndexOf(".");
          var pathIndex2 = path.length;
          var suffix = path.substring(pathIndex1 + 1, pathIndex2);//后缀名
          var fileLegalSuffix = util.fileLegalSuffix();
          if (fileLegalSuffix.indexOf(suffix) > -1) {
            var info = {};
            info.albumType = 5;
            info.type = 2;
            info.name = tempFile.name;
            info.ip = "";
            info.value = tempFile.path;
            info.size = tempFile.size;
            info.state = "2";
            info.dataType = "0";
            albumInfo.push(info);
            _this.setData({
              ["dataInfo.albumInfo"]: albumInfo
            })
          } else {
            util.dialogAlert("请选择" + String(fileLegalSuffix) + "格式的文件");
          }
        }
      })
    }
  },

  /**
   * 关闭链接错误提示
   */
  linkErrorDialogClose: function () {
    var _this = this;
    _this.setData({
      ["dataInfo.linkErrorDialogShow"]: false,
      isOpenDiaShow: false
    })
  },

  /**
  * 跳转到链接展示页面：日记
  */
  navigateToWebView: function (e) {
    var text = e.currentTarget.dataset.text;
    var type = e.currentTarget.dataset.type;
    if (type == 1) {
      wx.navigateTo({
        url: '../../../../../pages/home/webView/webView?src=' + text,
      })
    } else {
      wx.openDocument({
        filePath: text,
        success: function (res) {
        }
      })
    }
  },

  /**
   * 链接的焦点移出事件
   */
  albumInfoHrefInput: function (e) {
    var _this = this;
    var value = e.detail.value;
    var index = e.currentTarget.dataset.index;
    _this.setData({
      ["dataInfo.albumInfo[" + index + "].name"]: "",
      ["dataInfo.albumInfo[" + index + "].value"]: value,
      ["dataInfo.albumInfo[" + index + "].textareaPlaceholderShow"]: false
    })
    if (value.length <= 0) {
      _this.setData({
        ["dataInfo.albumInfo[" + index + "].textareaPlaceholderShow"]: true
      })
    }
  },

  /**
   * 链接的焦点移出事件
   */
  albumInfoHrefBlur: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    var value = _this.data.dataInfo.albumInfo[index].value;
    _this.setData({
      ["dataInfo.albumInfo[" + index + "].focus"]: false
    })
    if (_this.checkLink(index) && value.length > 0) {
      _this.setData({
        ["dataInfo.linkNameDialogShow"]: true,
        isOpenDiaShow: true,
        ["dataInfo.linkAlbumInfoIndex"]: index
      })
    }
  },

  /**
   * 公众号名称编辑事件
   */
  linkNameInput: function (e) {
    var _this = this;
    var name = e.detail.value;
    var index = _this.data.dataInfo.linkAlbumInfoIndex;
    _this.setData({
      ["dataInfo.albumInfo[" + index + "].name"]: name
    })
  },

  /**
   * 公众号名称弹窗关闭事件
   */
  linkNameDialogClose: function (e) {
    var _this = this;
    var index = _this.data.dataInfo.linkAlbumInfoIndex;
    var name = _this.data.dataInfo.albumInfo[index].name;
    if (name.length <= 0) {
      _this.setData({
        ["dataInfo.albumInfo[" + index + "].name"]: "公众号文章"
      })
    }
    _this.setData({
      ["dataInfo.linkNameDialogShow"]: false,
      isOpenDiaShow: true,
      ["dataInfo.linkAlbumInfoIndex"]: "",
      ["dataInfo.albumInfo[" + index + "].state"]: "2"
    })
  },

  /**
   * 校验链接
   */
  checkLink: function (index) {
    var _this = this;
    var albumInfo = _this.data.dataInfo.albumInfo[index];
    var type = albumInfo.type;
    if (type == 1) {
      var value = albumInfo.value.trim();
      var reg = /^https:\/\/mp.weixin.qq.com*/;
      if (value.length > 0 && !reg.test(value)) {
        _this.setData({
          ["dataInfo.linkErrorDialogShow"]: true,
          isOpenDiaShow: true
        })
        return false;
      }
    }
    return true;
  },

  /**
   * 位置
   */
  albumInfoPositionStart: function (albumInfo, type) {
    var _this = this;
    wx.chooseLocation({
      success: function (res) {
        var value = res.name;
        var latitude = res.latitude;
        var longitude = res.longitude;
        var address = res.address;
        if (value != null && value.length > 0) {
          var info = {};
          info.albumType = type;
          info.value = value;
          info.latitude = latitude;
          info.longitude = longitude;
          info.address = address;
          info.dataType = "0";
          albumInfo.push(info);
          _this.setData({
            ["dataInfo.albumInfo"]: albumInfo
          })
        } else {
          util.dialogAlert("未选中有效地址")
        }
      }
    })
  },

  /**
   * 是否显示推荐圈子的popup
   */
  recommendPopupShow: function () {
    var _this = this;
    var recommendPopupShow = _this.data.dataInfo.recommendPopupShow;
    _this.setData({
      ["dataInfo.recommendPopupShow"]: !recommendPopupShow,
      isOpenDiaShow: !recommendPopupShow
    })
  },

  /**
   * 推荐项目确认动作
   */
  recommendConfirm: function () {
    var _this = this;
    var value = [];
    var circleList = _this.data.tabs.circleList;
    var baobeiList = _this.data.tabs.baobeiList;
    for (var i = 0; i < circleList.length; i++) {
      if (circleList[i].circlesChecked) {
        console.log(circleList[i].showCirclesMoney)
        var valueInfo = {};
        valueInfo.recommendId = circleList[i].id;
        valueInfo.title = circleList[i].title;
        valueInfo.peopleNumber = circleList[i].renshu;
        valueInfo.clockNumber = circleList[i].qiandao;
        valueInfo.money = circleList[i].showCirclesMoney;
        valueInfo.image = circleList[i].beijing;
        valueInfo.isCommission = circleList[i].isCommission;
        valueInfo.type = "1";//1圈子  2宝贝
        value.push(valueInfo);
      }
    }
    for (var i = 0; i < baobeiList.length; i++) {
      if (baobeiList[i].circlesChecked) {

      }
    }
    if (value.length > 0) {
      var desc = _this.data.dataInfo.recommendInfo.desc;
      var info = {};
      info.desc = (desc == null || desc.length <= 0 ? "" : desc);
      info.value = value;
      info.dataType = "0";
      info.focus = true;
      _this.setData({
        ["dataInfo.recommendInfo"]: info
      })
    } else {
      _this.setData({
        ["dataInfo.recommendInfo"]: {}
      })
    }
    _this.recommendPopupShow();
  },

  /**
   * 推荐圈子简介输入时事件
   */
  tjTextareaInput: function (e) {
    var _this = this;
    var desc = e.detail.value;
    _this.setData({
      ["dataInfo.recommendInfo.desc"]: desc
    })
  },

  /**
   * 推荐圈子简介输入完成事件
   */
  tjTextareaBlur: function (e) {
    var _this = this;
    _this.setData({
      ["dataInfo.recommendInfo.focus"]: false
    })
  },

  /**
   * 推荐圈子简介获取焦点事件
   */
  tjTextareaTap: function () {
    var _this = this;
    _this.setData({
      ["dataInfo.recommendInfo.focus"]: true
    })
  },

  /**
   * 推荐的tabs切换
   */
  recommendTabsChange: function (event) {
    var _this = this;
    var index = event.detail.index;
    _this.setData({
      ["tabs.tabsActive"]: index
    })
  },

  /**
   * 推荐信息选中事件
   */
  recommendClick: function (e) {
    var _this = this;
    var type = e.currentTarget.dataset.type;
    var index = e.currentTarget.dataset.index;
    var circleList = _this.data.tabs.circleList;
    var baobeiList = _this.data.tabs.baobeiList;
    var count = 0;
    for (var i = 0; i < circleList.length; i++) {
      if (circleList[i].circlesChecked) {
        count = count + 1;
      }
    }
    for (var i = 0; i < baobeiList.length; i++) {
      if (baobeiList[i].circlesChecked) {
        count = count + 1;
      }
    }
    if (type == 1) {
      var circlesChecked = circleList[index].circlesChecked;
      if (!circlesChecked && count >= 3) {
        return;
      }
      _this.setData({
        ["tabs.circleList[" + index + "].circlesChecked"]: !circlesChecked
      })
    } else if (type == 2) {
      var circlesChecked = baobeiList[index].circlesChecked;
      if (!circlesChecked && count >= 3) {
        return;
      }
      _this.setData({
        ["tabs.baobeiList[" + index + "].circlesChecked"]: !circlesChecked
      })
    }
  },

  /**
   * 加载推荐圈子
   */
  loadRecommendedCircles: function () {
    var _this = this;
    var openid = app.globalData.logininfo.openid;
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        var data = {};
        data.openid = openid;
        data.circleid = _this.data.circleid;
        data.access_token = res.access_token;
        util.post(api.Interest_getUserRecommendInfoApiUrl, data).then(res => {
          if (res.code == 200) {
            var json = res.result.json;
            _this.setData({
              ["tabs.circleList"]: json.circleList,
              ["tabs.baobeiList"]: json.baobeiList
            })
            var recommendInfo_value = _this.data.dataInfo.recommendInfo.value;
            var circleList = _this.data.tabs.circleList;
            var baobeiList = _this.data.tabs.baobeiList;
            if (recommendInfo_value != null && recommendInfo_value.length > 0) {
              for (var i = 0; i < recommendInfo_value.length; i++) {
                var re = recommendInfo_value[i];
                var re_recommendId = re.recommendId;
                var re_type = re.type;
                if (re_type == 1) {
                  for (var j = 0; j < circleList.length; j++) {
                    if (re_recommendId == circleList[j].id) {
                      _this.setData({
                        ["tabs.circleList[" + j + "].circlesChecked"]: true
                      })
                    }
                  }
                } else if (re_type == 2) {
                  for (var j = 0; j < baobeiList.length; j++) {
                    if (re_recommendId == baobeiList[j].id) {
                      _this.setData({
                        ["tabs.baobeiList[" + j + "].circlesChecked"]: true
                      })
                    }
                  }
                }
              }
            }
          }
        })
      })
    }
  },

  /**
   * 关闭创建成功弹窗
   */
  energyInfoResultClose: function () {
    var _this = this;
    _this.setData({
      energyInfoResultShow: false
    })
  },

  /**
   * 兴趣专辑详情上移
   */
  albumLast: function (e) {
    var _this = this;
    var index = e.currentTarget.dataset.index;
    if (index == 0) {
      // 第一个元素不能往前移动
      return false;
    }
    var isRecorderStart = _this.data.dataInfo.isRecorderStart;
    if (isRecorderStart) {
      // 录音中，不能上移
      return false;
    }
    var albumInfo = _this.data.dataInfo.albumInfo;
    albumInfo.splice(index - 1, 0, albumInfo[index]);
    albumInfo.splice(index + 1, 1);
    _this.setData({
      ["dataInfo.albumInfo"]: albumInfo
    })
  },

  /**
   * 兴趣专辑详情下移
   */
  albumNext: function (e) {
    var _this = this;
    var albumInfo = _this.data.dataInfo.albumInfo;
    var index = e.currentTarget.dataset.index;
    if (index + 1 == albumInfo.length) {
      // 第一个元素不能往后移动
      return false;
    }
    var isRecorderStart = _this.data.dataInfo.isRecorderStart;
    if (isRecorderStart) {
      // 录音中，不能下移
      return false;
    }
    albumInfo.splice(index + 2, 0, albumInfo[index]);
    albumInfo.splice(index, 1);
    _this.setData({
      ["dataInfo.albumInfo"]: albumInfo
    })
  },

  /**
   * 兴趣专辑详情删除:弹出dialog
   */
  albumDeleteDialogShow: function (e) {
    var _this = this;
    var albumInfoDeleteIndex = e.currentTarget.dataset.index;
    _this.setData({
      ["dataInfo.albumInfoDeleteIndex"]: albumInfoDeleteIndex,
      ["dataInfo.voiceDialogDeleteShow"]: true,
      isOpenDiaShow: true
    })
  },

  /**
   * 兴趣专辑详情关闭dialog
   */
  albumDeleteDialogClose: function (e) {
    var _this = this;
    if (e.detail == "confirm") {
      var albumInfoDeleteIndex = _this.data.dataInfo.albumInfoDeleteIndex;
      if (albumInfoDeleteIndex == "-1") {
        _this.setData({
          ["dataInfo.appreciateInfo"]: {},
        })
      } else if (albumInfoDeleteIndex == "-2") {
        _this.setData({
          ["dataInfo.recommendInfo"]: {},
        })
      } else {
        var albumInfo = _this.data.dataInfo.albumInfo;
        var albumType = albumInfo[albumInfoDeleteIndex].albumType;
        var state = albumInfo[albumInfoDeleteIndex].state;
        if (albumType == "3" && state == "1") {
          // 删除录音：因为录音会触发录音动作，需要先删除录音动作再进行删除view
          _this.setData({
            ["dataInfo.albumInfo[" + albumInfoDeleteIndex + "].isVoiceDialogShow"]: false
          })
          _this.doClearInterval();
          recorderManager.stop();
        }
        albumInfo.splice(albumInfoDeleteIndex, 1);
        _this.setData({
          ["dataInfo.albumInfo"]: albumInfo
        })
      }
    }
    _this.setData({
      ["dataInfo.albumInfoDeleteIndex"]: "",
      ["dataInfo.voiceDialogDeleteShow"]: false,
      isOpenDiaShow: false
    })
  },

  /**
   * 创建圈子的画布
   */
  createCircleCanvas: function () {
    var _this = this;
    var circleInfo = _this.data.circleInfo;
    var interestJoinList = _this.data.interestJoinList;
    var title = circleInfo.title;
    var desc = circleInfo.ordInterestJoinCount + "人参加 | " + circleInfo.diaryCount + "次打卡";
    var posterImage = circleInfo.postersIp + circleInfo.posterImageUrl;
    var main_image1 = _this.data.mainUser.avatarip + _this.data.mainUser.avatarpath;
    var main_image2 = _this.data.mainUser.avatarurl;
    var userImage1 = main_image1 != null && main_image1.length > 0 ? main_image1 : main_image2;
    var userImage2 = "";
    for (var i = 0; i < interestJoinList.length; i++) {
      var userInfo = interestJoinList[i].userInfo;
      if (interestJoinList[i].identitytype != 1) {
        userImage2 = userInfo.avatarpath != null && userInfo.avatarpath.length > 0 ? userInfo.avatarip + userInfo.avatarpath : userInfo.avatarurl;
        break;
      }
    }
  },

  /**
  * 获取组员信息
  */
  getInterestJoin: function () {
    var _this = this;
    var data = {};
    data.circleid = _this.data.circleid;
    data.pageNum = 1;
    data.pageSize = 10;
    var openid = app.globalData.logininfo.openid;
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        data.openid = openid;
        data.access_token = res.access_token;
        _this.getInterestJoinQuery(api.Home_GetInterestJoinApiUrl, data);
      })
    } else {
      _this.getInterestJoinQuery(api.Home_GetInterestJoinUrl, data);
    }
  },

  /**
   * 获取组员：请求
   */
  getInterestJoinQuery: function (url, data) {
    var _this = this;
    util.post(url, data).then(function (res) {
      if (res.code == 200) {
        var resultList = res.result.list;
        var list = _this.data.interestJoinList;
        for (var i = 0; i < resultList.length; i++) {
          list.push(resultList[i]);
        }
        _this.setData({
          interestJoinList: list
        })
        // 请求完组员后，进行画布创建
        _this.createCircleCanvas();
      }
    });
  },

  /**
   * 修改海报
   */
  updatePostersUrl: function () {
    wx.navigateTo({
      url: '../../../../pages/background/background?type=2&title=设置圈子海报'
    })
  },

  /**
   * 获取圈子信息
   */
  getCircleInfo: function () {
    var _this = this;
    var data = { "circleid": _this.data.circleid };
    util.post(api.Interest_getCircleInfoByEditorUrl, data).then(function (res) {
      if (res.code == 200) {
        var json = res.result.json;
        _this.setData({
          mainUser: json.mainUser,
          dataInfo: json.dataInfo,
          circleInfo: json.circleInfo,
          selectAllLable: json.selectAllLable,
          selectLableTextArray: json.selectLableTextArray
        })
        // 获取成员信息
        _this.getInterestJoin();
        // 加载推荐信息
        _this.loadRecommendedCircles();
        // 加载圈子付费设置的价格范围以及时间
        _this.getAmountScope();
      }
    });
  },

  /**
   * 标题移入事件
   */
  titleFocus: function (e) {
    var _this = this;
    _this.setData({
      ["circleInfo.titleFocus"]: true
    })
  },

  /**
   * 副标题移入事件
   */
  subheadingFocus: function (e) {
    var _this = this;
    _this.setData({
      ["circleInfo.subheadingFocus"]: true
    })
  },

  /**
   * 标题输入事件
   */
  titleInput: function (e) {
    var _this = this;
    var title = e.detail.value;
    if (title.length <= 0) {
      util.dialogAlert("主标题不能为空\r\n输入最多15个字符");
    }
    _this.setData({
      ["circleInfo.title"]: title
    })
  },

  /**
   * 副标题输入事件
   */
  subheadingInput: function (e) {
    var _this = this;
    _this.setData({
      ["circleInfo.subheading"]: e.detail.value
    })
  },

  /**
   * 跳转项目标签
   */
  doitemlabel: function (event) {
    var _this = this;
    wx.navigateTo({
      url: '../publish/itemlabel/itemlabel?selectAllLable=' + JSON.stringify(_this.data.selectAllLable)
    })
  },

  /**
   * 保存圈子
   */
  saveCircleInfo: function (e) {
    var _this = this;
    // 类型：1保存并预览  2去圈子互动页
    var type = e.currentTarget.dataset.type;
    var openid = app.globalData.logininfo.openid;
    if (openid == null || openid.length <= 0) {
      util.dialogAlert("请先登录");
      return false;
    }
    // 进行圈子信息校验
    if (!_this.checkCircleInfo()) {
      return false;
    }
    wx.showLoading({
      title: '保存中',
    }, 30000)

    // 上传所有文件并提交
    _this.uploadFileAndSubmit(type);
  },

  /**
   * 校验圈子
   */
  checkCircleInfo: function () {
    var _this = this;
    var circleInfo = _this.data.circleInfo;
    var title = circleInfo.title;
    var selectAllLable = _this.data.selectAllLable;
    if (title == null || title.length <= 0) {
      util.dialogAlert("主标题不能为空\r\n输入最多15个字符");
      return false;
    } else if (selectAllLable.length <= 0) {
      util.dialogAlert("请选择圈子的类目标签");
      return false;
    }
    return true;
  },

  /**
   * 上传所有文件并提交
   */
  uploadFileAndSubmit: function (type) {
    var _this = this;
    var circleInfo = _this.data.circleInfo;
    var albumInfo = _this.data.dataInfo.albumInfo;
    var uploadInfoList = [];// 用来存放所有的上传内容
    // 检查海报是否需要上传
    var postersIsupload = circleInfo.postersIsupload;
    if (postersIsupload) {
      var uploadInfo = {};
      uploadInfo.type = "1";
      uploadInfo.filePath = circleInfo.posterImageUrl;
      uploadInfoList.push(uploadInfo);
    }
    // 检查图片是否需要上传
    for (var i = 0; i < albumInfo.length; i++) {
      var dataType = albumInfo[i].dataType;
      var albumType = albumInfo[i].albumType;
      if (dataType == "0") {// 0手动添加的  1从数据库获取的
        if (albumType == "2") {
          // 图片
          var tempFiles = albumInfo[i].tempFiles;
          for (var j = 0; j < tempFiles.length; j++) {
            var uploadInfo = {};
            uploadInfo.type = "2";
            uploadInfo.albumInfoIndex = i;
            uploadInfo.tempFilesIndex = j;
            uploadInfo.filePath = tempFiles[j].path;
            uploadInfoList.push(uploadInfo);
          }
        }
        if (albumType == "3") {
          // 音频
          var uploadInfo = {};
          uploadInfo.type = "3";
          uploadInfo.albumInfoIndex = i;
          uploadInfo.filePath = albumInfo[i].src;
          uploadInfoList.push(uploadInfo);
        }
        if (albumType == "4") {
          // 视频
          var uploadInfo = {};
          uploadInfo.type = "4";
          uploadInfo.albumInfoIndex = i;
          uploadInfo.filePath = albumInfo[i].src;
          uploadInfoList.push(uploadInfo);
        }
        if (albumType == "5" && albumInfo[i].type == 2) {
          // 链接
          var uploadInfo = {};
          uploadInfo.type = "5";
          uploadInfo.albumInfoIndex = i;
          uploadInfo.filePath = albumInfo[i].value;
          uploadInfoList.push(uploadInfo);
        }
      }
    }
    if (uploadInfoList.length > 0) {
      // 开始请求:要先上传
      _this.uploadFileQuery(uploadInfoList, 0, type);
    } else {
      _this.saveAlbumInfo(type);
    }
  },

  /**
   * 上传所有文件：执行请求
   */
  uploadFileQuery: function (data, queryIndex, type) {
    var _this = this;
    var queryData = data[queryIndex];
    var queryUrl = "";
    switch (queryData.type) {
      case "1":
        // 海报
        queryUrl = api.File_doImageUpload;
        break;
      case "2":
        // 图片
        queryUrl = api.File_doImageUpload;
        break;
      case "3":
        // 音频
        queryUrl = api.File_doAudioUpload;
        break;
      case "4":
        // 视频
        queryUrl = api.File_doVideoUpload;
        break;
      case "5":
        // 链接
        queryUrl = api.File_doOtherUpload;
        break;
    }

    wx.uploadFile({
      url: queryUrl,
      filePath: queryData.filePath,
      name: 'file',
      formData: {
        "type": "2"
      },
      success(res) {
        var data = JSON.parse(res.data);
        if (data.code == 200) {
          var ip = data.result.ip;
          var path = data.result.path;
          switch (queryData.type) {
            case "1":
              // 海报
              _this.setData({
                ["circleInfo.postersIp"]: ip,
                ["circleInfo.posterImageUrl"]: path,
              })
              break;
            case "2":
              // 图片
              var albumInfoIndex = queryData.albumInfoIndex;// 编辑详情中的下标
              var tempFilesIndex = queryData.tempFilesIndex;// 图片里的下标
              _this.setData({
                ["dataInfo.albumInfo[" + albumInfoIndex + "].tempFiles[" + tempFilesIndex + "].ip"]: ip,
                ["dataInfo.albumInfo[" + albumInfoIndex + "].tempFiles[" + tempFilesIndex + "].path"]: path
              })
              break;
            case "3":
              // 音频
              var albumInfoIndex = queryData.albumInfoIndex;// 编辑详情中的下标
              _this.setData({
                ["dataInfo.albumInfo[" + albumInfoIndex + "].ip"]: ip,
                ["dataInfo.albumInfo[" + albumInfoIndex + "].src"]: path
              })
              break;
            case "4":
              // 视频
              var albumInfoIndex = queryData.albumInfoIndex;// 编辑详情中的下标
              var ffmpegvideoimagepath = data.result.ffmpegvideoimagepath;
              _this.setData({
                ["dataInfo.albumInfo[" + albumInfoIndex + "].ip"]: ip,
                ["dataInfo.albumInfo[" + albumInfoIndex + "].src"]: path,
                ["dataInfo.albumInfo[" + albumInfoIndex + "].ffmpegvideoimagepath"]: ffmpegvideoimagepath
              })
              if (_this.data.albumInfo[albumInfoIndex].totalTime <= 0) {
                var width = data.result.width;
                var height = data.result.height;
                var duration = data.result.duration;
                _this.setData({
                  ["dataInfo.albumInfo[" + albumInfoIndex + "].width"]: width,
                  ["dataInfo.albumInfo[" + albumInfoIndex + "].height"]: height,
                  ["dataInfo.albumInfo[" + albumInfoIndex + "].totalTime"]: duration,
                  ["dataInfo.albumInfo[" + albumInfoIndex + "].totalDate"]: util.digitalFormatTime(duration)
                })
              }
              break;
            case "5":
              // 链接
              var albumInfoIndex = queryData.albumInfoIndex;// 编辑详情中的下标
              _this.setData({
                ["dataInfo.albumInfo[" + albumInfoIndex + "].ip"]: ip,
                ["dataInfo.albumInfo[" + albumInfoIndex + "].value"]: path
              })
              break;
          }
        }
      },
      fail(res) {
        // 失败
      },
      complete(res) {
        // 结束：
        if (queryIndex < data.length - 1) {
          // 图片未上传完成，继续上传
          queryIndex++;
          _this.uploadFileQuery(data, queryIndex, type);
        } else {
          // 上传完成，执行save圈子信息
          _this.saveAlbumInfo(type);
        }
      }
    })
  },

  /**
   * save圈子信息
   */
  saveAlbumInfo: function (type) {
    var _this = this;
    var circleInfo = _this.data.circleInfo;
    var dataInfo = _this.data.dataInfo;
    var selectAllLable = _this.data.selectAllLable;
    var saveCircleInfo = {};
    saveCircleInfo.title = circleInfo.title;
    saveCircleInfo.subheading = circleInfo.subheading;
    saveCircleInfo.postersIp = circleInfo.postersIp;
    saveCircleInfo.posterImageUrl = circleInfo.posterImageUrl;
    util.post(api.fetchToken()).then(function (res) {
      if (res.access_token != '') {
        return Promise.resolve({
          access_token: res.access_token
        });
      }
    }).then(function (res) {
      var data = {};
      data.access_token = res.access_token;
      data.openid = app.globalData.logininfo.openid;
      data.circleid = _this.data.circleid;// 圈子id
      data.dataInfo = JSON.stringify(dataInfo);// 圈子详情
      data.circleInfo = JSON.stringify(saveCircleInfo);// 圈子信息
      data.itemlabelData = JSON.stringify(selectAllLable);// 标签
      util.post(api.Interest_updateCircleInfoApiUrl, data).then(function (res) {
        if (res.code == 200) {
          wx.hideLoading();
          if (type == 0) {
            wx.navigateTo({
              url: '../editdetails/circledetails/circledetails?circleid=' + _this.data.circleid,
            })
          } else if (type == 1) {
            wx.redirectTo({
              url: '../editdetails/circleinteraction/circleinteraction?circleid=' + _this.data.circleid,
            })
          }
        }
      })
    })
  },

  /**
   * 语音拒绝授权的提示弹窗关闭
   */
  audioOauhRefusedDialogClose: function () {
    var _this = this;
    _this.setData({
      ["dataInfo.audioOauhRefusedDialogShow"]: false,
      isOpenDiaShow: false
    })
  },

  /**
   * 语音拒绝授权的提示弹窗确认动作
   */
  audioOauhRefusedDialogSuccess: function () {
    var _this = this;
    wx.openSetting({
      success: function (data) {
        if (data.authSetting["scope.record"] == true) {
          // 授权成功
          _this.audioOauhRefusedDialogClose();
        } else {
          // 授权失败
          _this.audioOauhRefusedDialogClose();
        }
      }
    })
  },

  /**
   * 地址拒绝授权的提示弹窗关闭
   */
  addressOauhRefusedDialogClose: function () {
    var _this = this;
    _this.setData({
      ["dataInfo.addressOauhRefusedDialogShow"]: false,
      isOpenDiaShow: false
    })
  },

  /**
   * 地址拒绝授权的提示弹窗确认动作
   */
  addressOauhRefusedDialogSuccess: function () {
    var _this = this;
    wx.openSetting({
      success: function (data) {
        if (data.authSetting["scope.userLocation"] == true) {
          // 授权成功
          _this.addressOauhRefusedDialogClose();
        } else {
          // 授权失败
          _this.addressOauhRefusedDialogClose();
        }
      }
    })
  },

  /**
   * 进入圈子设置页面
   */
  navigateToCircleopt: function () {
    var _this = this;
    var circleid = _this.data.circleid;
    wx.navigateTo({
      url: '../editdetails/circleopt/circleopt?circleid=' + circleid,
    })
  },

  /**
   * 加载圈子付费设置的价格范围以及时间
   */
  getAmountScope: function () {
    var _this = this;
    var openid = app.globalData.logininfo.openid;
    if (openid != null && openid != "") {
      // 已登录
      util.post(api.fetchToken()).then(function (res) {
        if (res.access_token != '') {
          return Promise.resolve({
            access_token: res.access_token
          });
        }
      }).then(function (res) {
        var param = {};
        param.access_token = res.access_token;
        param.openid = openid;
        param.circleid = _this.data.circleid;
        util.post(api.Interest_GetAmountScopeApi, param).then(function (res) {
          if (res.code == 200) {
            var interestData = res.result.interestData;
            _this.setData({
              ["dataInfo.returnMoneyText"]: interestData.returnMoneyText,
              ["dataInfo.returnPrice"]: interestData.returnPrice,
              ["dataInfo.returnPreferentialSettings"]: interestData.returnPreferentialSettings,
              ["dataInfo.returnAmountDetailSize"]: interestData.returnAmountDetailSize,
              ["dataInfo.returnItemTypeIdentification"]: interestData.returnItemTypeIdentification,
              ["dataInfo.returnProjectdateStart"]: interestData.returnProjectdateStart,
              ["dataInfo.returnProjectdateEnd"]: interestData.returnProjectdateEnd,
              ["dataInfo.returnProjectdateidentification"]: interestData.returnProjectdateidentification,
              ["dataInfo.preferentialdateStartMin"]: interestData.preferentialdateStartMin,
              ["dataInfo.preferentialdateEndMax"]: interestData.preferentialdateEndMax,
              ["dataInfo.validityStartMin"]: interestData.validityStartMin,
              ["dataInfo.validityEndMax"]: interestData.validityEndMax,
              ["dataInfo.projectdateStart"]: interestData.projectdateStart,
              ["dataInfo.projectdateStartLimit"]: interestData.projectdateStartLimit,
              ["dataInfo.projectdateEnd"]: interestData.projectdateEnd,
              ["dataInfo.projectdateEndLimit"]: interestData.projectdateEndLimit,
            })
          }
        })
      })
    }
  },

  /**
   * 跳转到票种页面
   */
  navigateToRegistrationfeeDetail: function(){
    var _this = this;
    var circleid = _this.data.circleid
    wx.navigateTo({
      url: '../editdetails/registrationfee/registrationfee2?circleid=' + circleid,
    })
  }
})